package com.yb.domain.goods;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.yb.base.annotation.Column;
import com.yb.base.annotation.Table;
import com.yb.base.entity.BaseEntity;
import com.yb.bussiness.goods.CategoryMessageService;
import com.yb.bussiness.goods.CategoryMessageServiceImpl;
import com.yb.bussiness.shoper.BrandService;
import com.yb.bussiness.shoper.BrandServiceImpl;

// default package

/**
 * TgBrand entity.
 * 
 * @author MyEclipse Persistence Tools
 */

@Table("t_g_brand")
public class TgBrand extends BaseEntity implements java.io.Serializable {
    
    @Column(name = "reject")
    private static CategoryMessageService service;
    static {
        service = new CategoryMessageServiceImpl();
    }
    
    // Fields
    private String name;
    
    private String code;
    
    private String brandDesc;
    
    private Integer categoryId;
    
    private String imgsrc;
    
    private String brandOrder;
    
    private String brandPic;
    
    private String shopAddress;
    
    private String phone;
    
    private String companyOPerer;
    
    private Long sysuserId;
    
    private String auding;
    
    private String realName;
    
    private String sex;
    
    private String tel;
    
    private String companyName;
    
    private String accTitle;
    
    private String announcement;
    
    @Column(name = "reject")
    private String firseBrandName;
    
    @Column(name = "reject")
    private String secondBrandName;
    
    @Column(name = "reject")
    private Long cid;
    
    @Column(name = "reject")
    private String storeContent;
    
    @Column(name = "reject")
    private String storeDesc;
    
    @Column(name = "reject")
    private String brandDescShort;
    
    @Column(name = "reject")
    private String nameShort;
    
    private String stateMent;
    
    @Column(name = "reject")
    private String typeId;
    
    private String activityFlag;
    
    public String getBrandDescShort() {
        if (null != brandDesc) {
            brandDescShort = getShortDesc(brandDesc);
            if (brandDescShort == brandDesc) {
                brandDescShort = "暂无信息";
            }
        }
        if (null != brandDescShort)
            if (brandDescShort.length() > 200)
                brandDescShort = brandDescShort.substring(0, 200) + "...";
        return brandDescShort;
    }
    
    private String getShortDesc(String str) {
        String temp = "";
        Pattern patt = Pattern.compile(">[*[^<]]+<");
        Matcher m = patt.matcher(brandDesc);
        while (m.find()) {
            String contentDesc = "";
            contentDesc = m.group(0);
            contentDesc = contentDesc.substring(1, contentDesc.length() - 1);
            contentDesc =
                contentDesc.replaceAll("\\r", "")
                    .replaceAll("\\n", "")
                    .replaceAll("\\t", "")
                    .replaceAll(" ", "")
                    .replaceAll("&nbsp;", "");
            temp += contentDesc;
            if (temp.length() >= 50)
                break;
        }
        return temp;
    }
    
    public String getShortName() {
        String temp = "";
        if (null != name) {
            temp = name.replaceAll(" ", "").trim();
            if (temp.length() > 5) {
                temp = temp.substring(0, 2) + "…" + temp.substring(temp.length() - 2);
            }
            return temp;
        }
        if (name == null)
            this.name = "";
        return this.name.trim();
    }
    
    public void setBrandDescShort(String brandDescShort) {
        this.brandDescShort = brandDescShort;
    }
    
    public String getCompanyName() {
        return companyName;
    }
    
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }
    
    public String getAuding() {
        return auding;
    }
    
    public void setAuding(String auding) {
        this.auding = auding;
    }
    
    public Long getSysuserId() {
        return sysuserId;
    }
    
    public void setSysuserId(Long sysuserId) {
        this.sysuserId = sysuserId;
    }
    
    public String getShopAddress() {
        return shopAddress;
    }
    
    public void setShopAddress(String shopAddress) {
        this.shopAddress = shopAddress;
    }
    
    public String getPhone() {
        return phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    public String getCompanyOPerer() {
        return companyOPerer;
    }
    
    public void setCompanyOPerer(String companyOPerer) {
        this.companyOPerer = companyOPerer;
    }
    
    public String getBrandPic() {
        return brandPic;
    }
    
    public void setBrandPic(String brandPic) {
        this.brandPic = brandPic;
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getCode() {
        return this.code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public String getBrandDesc() {
        return this.brandDesc;
    }
    
    public void setBrandDesc(String brandDesc) {
        this.brandDesc = brandDesc;
    }
    
    public Integer getCategoryId() {
        return this.categoryId;
    }
    
    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }
    
    public String getImgsrc() {
        return this.imgsrc;
    }
    
    public void setImgsrc(String imgsrc) {
        this.imgsrc = imgsrc;
    }
    
    public String getBrandOrder() {
        return this.brandOrder;
    }
    
    public void setBrandOrder(String brandOrder) {
        this.brandOrder = brandOrder;
    }
    
    public String getFirseBrandName() {
        return firseBrandName;
    }
    
    public void setFirseBrandName(String firseBrandName) {
        this.firseBrandName = firseBrandName;
    }
    
    public String getSecondBrandName() {
        return secondBrandName;
    }
    
    public void setSecondBrandName(String secondBrandName) {
        this.secondBrandName = secondBrandName;
    }
    
    public String getRealName() {
        return realName;
    }
    
    public void setRealName(String realName) {
        this.realName = realName;
    }
    
    public String getSex() {
        return sex;
    }
    
    public void setSex(String sex) {
        this.sex = sex;
    }
    
    public String getTel() {
        return tel;
    }
    
    public void setTel(String tel) {
        this.tel = tel;
    }
    
    public String getAnnouncement() {
        if (null == announcement) {
            announcement = service.getAnnouncement(getCid());
        }
        return announcement;
    }
    
    public String getAnnouncementShort() {
        if (null != getAnnouncement()) {
            String temp = getShortDesc();
            if("".equals(temp))
            	temp = getAnnouncement();
            if(temp.length()>50){
            	String temp1 = temp.replaceAll("&nbsp;", "");
            	if(temp1.length()>50)
            		return temp1.substring(0, 50);
            	return temp1;
            }
            else{
            	return temp;
            }
        }
        return announcement;
    }
    
    private String getShortDesc() {
        if (null == getAnnouncement())
            return "";
        String temp = "";
        Pattern patt = Pattern.compile(">[*[^<]]+<");
        Matcher m = patt.matcher(getAnnouncement());
        while (m.find()) {
            String contentDesc = "";
            contentDesc = m.group(0);
            contentDesc = contentDesc.substring(1, contentDesc.length() - 1);
            contentDesc =
                contentDesc.replaceAll("\\r", "")
                    .replaceAll("\\n", "")
                    .replaceAll("\\t", "")
                    .replaceAll(" ", "")
                    .replaceAll("&nbsp;", "");
            temp += contentDesc;
        }
        return temp;
    }
    
    public void setAnnouncement(String announcement) {
        this.announcement = announcement;
    }
    
    public Long getCid() {
        if (null == cid) {
            BrandService goodService = new BrandServiceImpl();
            cid = goodService.findCidByBrandId(getId());
        }
        return cid;
    }
    
    public void setCid(Long cid) {
        this.cid = cid;
    }
    
    public String getAccTitle() {
        return accTitle;
    }
    
    public String getStoreContent() {
        return storeContent;
    }
    
    public void setStoreContent(String storeContent) {
        this.storeContent = storeContent;
    }
    
    public String getStoreDesc() {
        return storeDesc;
    }
    
    public void setStoreDesc(String storeDesc) {
        this.storeDesc = storeDesc;
    }
    
    public void setAccTitle(String accTitle) {
        this.accTitle = accTitle;
    }
    
    public String getNameShort() {
        if (null != name)
            if (name.length() > 5)
                nameShort = name.substring(0, 2) + "…" + name.substring(name.length() - 2);
            else
                nameShort = name;
        return nameShort;
    }
    
    public void setNameShort(String nameShort) {
        this.nameShort = nameShort;
    }
    
    public String getStateMent() {
        if (null == stateMent) {
            stateMent = service.getStateMent(getCid());
        }
        return stateMent;
    }
    
    public void setStateMent(String stateMent) {
        this.stateMent = stateMent;
    }
    
    public String getTypeId() {
        return typeId;
    }
    
    public void setTypeId(String typeId) {
        this.typeId = typeId;
    }

    public String getActivityFlag() {
        return activityFlag;
    }

    public void setActivityFlag(String activityFlag) {
        this.activityFlag = activityFlag;
    }
    
}